﻿using System;

namespace 多态模拟U盘_硬盘
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            MobileDisk md = new MobileDisk();
            UDisk u = new UDisk();
            MP3Disk mp3 = new MP3Disk();
            Comeputer cpu = new Comeputer();
            cpu.CpuRead(md);
            cpu.CpuWrite(md);
            Console.ReadKey();
        }
    }

    /// <summary>
    /// 抽象父类 移动存储
    /// </summary>
    public abstract class MobileStorage
    {
        public abstract void Read();

        public abstract void Write();
    }

    /// <summary>
    /// 移动硬盘
    /// </summary>
    public class MobileDisk : MobileStorage
    {
        public override void Read()
        {
            Console.WriteLine("硬盘在读取数据");
        }

        public override void Write()
        {
            Console.WriteLine("硬盘在读取数据");
        }
    }

    /// <summary>
    /// MP3
    /// </summary>
    public class MP3Disk : MobileStorage
    {
        public override void Read()
        {
            Console.WriteLine("MP3在读取数据");
        }

        public override void Write()
        {
            Console.WriteLine("MP3在写入数据");
        }

        public void PlayMusic()
        {
            Console.WriteLine("MP3在放歌");
        }
    }

    /// <summary>
    /// U盘
    /// </summary>
    public class UDisk : MobileStorage
    {
        public override void Read()
        {
            Console.WriteLine("U盘在读取数据");
        }

        public override void Write()
        {
            Console.WriteLine("U盘在读取数据");
        }
    }

    /// <summary>
    /// 电脑CPU
    /// </summary>
    public class Comeputer
    {
        public void CpuRead(MobileStorage ms)
        {
            ms.Read();
        }

        public void CpuWrite(MobileStorage ms)
        {
            ms.Write();
        }
    }
}